package dongze.com.ckdj.adapter;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.Date;
import java.util.List;

import dongze.com.ckdj.R;
import dongze.com.ckdj.data.entity.response.GetVinMapResponse;
import dongze.com.ckdj.databinding.ParkLotQueryListItemBinding;
import dongze.com.ckdj.databinding.model.ParkLotQueryListItemModel;

/**
 * Created by fanqwz on 2017/11/30.
 */

public class ParkLotQueryAdapter extends RecyclerView.Adapter<ParkLotQueryAdapter.ViewHolder> {
    ParkLotQueryListItemModel[] models;
    List<GetVinMapResponse> list;
    public ParkLotQueryAdapter(List<GetVinMapResponse> list) {
        this.list = list;
        models = new ParkLotQueryListItemModel[list == null ? 0 : list.size()];

        for (int i = 0; i < models.length; i++) {
            models[i] = new ParkLotQueryListItemModel();
            models[i].area.set(list.get(i).getQyName());
            models[i].brand.set(list.get(i).getBrand());
            models[i].lane.set(list.get(i).getLaneName());
            models[i].pos.set(String.valueOf(list.get(i).getSort()));
            models[i].time.set(list.get(i).getcTime());
            models[i].user.set(list.get(i).getUserName());
            models[i].vin.set(list.get(i).getVin());
            models[i].voyage.set(list.get(i).getVoyage());
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ParkLotQueryListItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.park_lot_query_list_item, parent, false);
        return new ViewHolder(binding.getRoot(), binding);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.binding.setModel(models[position]);
    }

    @Override
    public int getItemCount() {
        return models.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ParkLotQueryListItemBinding binding;

        public ViewHolder(View itemView, ParkLotQueryListItemBinding binding) {
            super(itemView);
            this.binding = binding;
        }
    }
}
